package com.qiniuyun.threedgenerator.repository;

import com.qiniuyun.threedgenerator.entity.ModelHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;

public interface ModelHistoryRepository extends JpaRepository<ModelHistory, Long> {

    List<ModelHistory> findByUserId(Long userId);

    List<ModelHistory> findByStatus(String status);

    List<ModelHistory> findByUserUsernameOrderByCreatedAtDesc(String username);

    Optional<ModelHistory> findByIdAndUserId(Long id, Long userId);

    @Query("SELECT m FROM ModelHistory m WHERE m.user.id = :userId AND m.status = :status ORDER BY m.createdAt DESC")
    List<ModelHistory> findByUserIdAndStatus(@Param("userId") Long userId, @Param("status") String status);

    long countByUserId(Long userId);

    long countByStatus(String status);
}